﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ContinentsAndTowns.aspx.cs" Inherits="Continents.ContinentsAndTowns" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="main" runat="server">
    <asp:EntityDataSource ID="EntityContinents" runat="server"
        ConnectionString="name=ContinentsAndTownsEntities" DefaultContainerName="ContinentsAndTownsEntities"
        EnableInsert="True" EnableUpdate="True" EnableDelete="True" 
        EntitySetName="Continents" EnableFlattening="False">
    </asp:EntityDataSource>

    <asp:EntityDataSource ID="EntityCountries" runat="server"
        ConnectionString="name=ContinentsAndTownsEntities" DefaultContainerName="ContinentsAndTownsEntities"
        EnableInsert="True" EnableUpdate="True" EnableDelete="True" 
        EntitySetName="Countries" EnableFlattening="False" Where="it.[ContinentID]==@contID">
        <WhereParameters><asp:ControlParameter Type="Int32" Name="contID" ControlID="Continents" DefaultValue="0" /></WhereParameters>
    </asp:EntityDataSource>

    <asp:EntityDataSource ID="EntityTowns" runat="server"
        ConnectionString="name=ContinentsAndTownsEntities" DefaultContainerName="ContinentsAndTownsEntities"
        EntitySetName="Towns" Where="it.[CountryID]==@cntryID">
        <WhereParameters><asp:ControlParameter Type="Int32" Name="cntryID" ControlID="Countries" DefaultValue="0" /></WhereParameters>
    </asp:EntityDataSource>
    
    <asp:ListBox ID="Continents" runat="server" DataSourceID="EntityContinents" AutoPostBack="true"
        DataTextField="Name" DataValueField="ContinentID">
    </asp:ListBox>

    <asp:GridView ID="Countries" runat="server" DataSourceID="EntityCountries"
        AutoGenerateColumns="False"
        AllowSorting="True" DataKeyNames="CountryID">
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
            <asp:BoundField DataField="Language" HeaderText="Language" 
                SortExpression="Language" />
            <asp:BoundField DataField="Population" HeaderText="Population" 
                SortExpression="Population" />
        </Columns>
    </asp:GridView>

    <asp:ListView ID="Cities" runat="server" DataSourceID="EntityTowns"
        AutoGenerateColumns="False" AllowPaging="True" 
        AllowSorting="True" DataKeyNames="TownID">
        <ItemTemplate>
            <div id="item">
                Name:
                <asp:Literal Mode="Encode" ID="LiteralTownName" runat="server" Text='<%# Eval("Name") %>' />
                <br />
                Population:
                <asp:Literal Mode="Encode" ID="Literal1" runat="server" Text='<%# Eval("Population") %>' />
            </div>
        </ItemTemplate>
    </asp:ListView>
    </form>
</body>
</html>
